// import Mock from 'mockjs'
import md5 from "md5";
export default [
  {
    url: '/api/user/login',
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body;

      const checkUser = getUser().find(
        (item) => username === item.username && password === md5(item.password)
      );

      if (!checkUser) {
        return {
          code: 0,
          data: { message: '用户名或密码错误' },
        };
      }

      return {
        code: 200,
        data: {
          message: '登录成功',
          token: checkUser.token,
          avatar: checkUser.avatar
        },
      };
    },
  },
];

function getUser() {
  return [
    {
      userId: 1,
      username: 'admin',
      password: 'admin1234',
      avatar:
        'https://bpic.588ku.com/element_origin_min_pic/23/07/11/d32dabe266d10da8b21bd640a2e9b611.jpg!r650',
      roles: '管理员',
      token: crypto.randomUUID()
    },
  ];
}
